package com.woniu.after.service.impl;

import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.after.entity.TOrderExpress;
import com.woniu.after.entity.dto.OrderAfteIogisticsDto;
import com.woniu.after.mapper.TOrderAfterMapper;
import com.woniu.after.service.TOrderExpressService;
import com.woniu.after.mapper.TOrderExpressMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
* @author Kenneon
* @description 针对表【t_order_express(订单物流)】的数据库操作Service实现
* @createDate 2024-05-28 13:12:23
*/
@Service
public class TOrderExpressServiceImpl extends ServiceImpl<TOrderExpressMapper, TOrderExpress>
    implements TOrderExpressService{
    @Autowired
    private TOrderAfterMapper afterMapper;
    @Value("${snowflake.workId}")
    private long workId;
    @Value("${snowflake.datacenterId}")
    private long datacenterId;

    @Override
    public void addExpress(Long detailNum) {
        long orderId = IdUtil.getSnowflake(workId, datacenterId).nextId();
        OrderAfteIogisticsDto orderAfteIogisticsDto = afterMapper.queryOrderIoInfo(detailNum);
        TOrderExpress tOrderExpress = new TOrderExpress();
        tOrderExpress.setCompanyName("东风快递");
        tOrderExpress.setCompanyCode("DFO");
        tOrderExpress.setExpressCode(String.valueOf("DF"+orderId));
        tOrderExpress.setStartPlace(orderAfteIogisticsDto.getStartPlace());
        tOrderExpress.setStartAddr(orderAfteIogisticsDto.getStartAddr());
        tOrderExpress.setStartArea(orderAfteIogisticsDto.getStartArea());
        tOrderExpress.setStartProvince(orderAfteIogisticsDto.getStartProvince());
        tOrderExpress.setEndPlace(orderAfteIogisticsDto.getEndPlace());
        tOrderExpress.setEndAddr(orderAfteIogisticsDto.getEndAddr());
        tOrderExpress.setEndArea(orderAfteIogisticsDto.getEndArea());
        tOrderExpress.setEndProvince(orderAfteIogisticsDto.getEndProvince());
        tOrderExpress.setOrderDetailId(detailNum);
        save(tOrderExpress);
    }
}




